package misp_backend.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import misp_backend.config.AjaxResult;
import misp_backend.domain.Category;
import misp_backend.domain.Dishes;
import misp_backend.service.CategoryService;
import misp_backend.service.DishesService;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Update;
import org.apache.logging.log4j.util.PerformanceSensitive;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/dishes")
public class DishController {
    @Autowired
    private DishesService dishesService;
    @Autowired
    private CategoryService categoryService;
    @GetMapping("/test")
    public String test(){
        return "helloSpirng";
    }
//    @PreAuthorize("hasAnyRole('admin')")
    @GetMapping("/all")
public AjaxResult listAllDishes(){
    return AjaxResult.success(dishesService.listWithCategoryName());
}
@PostMapping("/add")
public AjaxResult addNewDish(@RequestBody Dishes dishes){
    Date time=new Date();
 dishes.setCreateTime(time);
        return AjaxResult.success(dishesService.save(dishes));
}
@PostMapping("/update")
    public AjaxResult updateDish(@RequestBody Dishes dishes){
    Date time=new Date();
    dishes.setUpdateTime(time);

        return AjaxResult.success(dishesService.updateById(dishes));
}
@DeleteMapping("/remove")
public AjaxResult removeDish(@RequestParam Long dishid){
        return AjaxResult.success(dishesService.removeById(dishid));

}
@GetMapping("/getappitite")
    public AjaxResult getappitite(@RequestParam Long dishid){
        return AjaxResult.success(dishesService.getDishTypeDetail(dishid));
}
}
